<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Tree原生使用_夏小蕾</title>
    <link rel="stylesheet" href="./frame/easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" href="./frame/easyui/themes/icon.css">
    <link rel="stylesheet" href="./frame/bootstrap/css/bootstrap.min.css">
</head>

<body>
    <ul id="tt" class="easyui-tree">
    </ul>    
    <script src='./frame/jquery-3.3.1.min.js'></script>
    <script src='./frame/easyui/jquery.easyui.min.js'></script>
    <script>
        $('#tt').tree({
            url: '/user/tree',
            method: 'get',
            checkbox: true,
            loadFilter: function (result) {
                return format(result.data)
            }
        })
        function format(data, pid = 0, res = []) {
            data.forEach(function (row) {
                if (row.pid == pid) {
                    row.children = [],
                        res.push(row)
                    format(data, row.id, row.children)
                }
            })
            return res
        }
    </script>
</body>

</html>